<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxRefund;
use App\Wen\Utils\Settings;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxRefundController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $app_coin_name = Settings::get('app_coin_name', '硬币');
        return Grid::make(new WxRefund(), function (Grid $grid) use ($app_coin_name){
            $grid->simplePaginate();
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('order_good_id');
            $grid->column('order_id');
            $grid->column('goods_id');
            $grid->column('product_id');
            $grid->column('amount');
            $grid->column('amount')->display(function ($v) use ($app_coin_name){
                if($this->credit_type == 1){
                    return '￥'.$v;
                }else{
                    return $v.$app_coin_name;
                }
            })->sortable();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableBatchActions();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxRefund(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('order_good_id');
            $show->field('order_id');
            $show->field('goods_id');
            $show->field('product_id');
            $show->field('amount');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxRefund(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('order_good_id');
            $form->text('order_id');
            $form->text('goods_id');
            $form->text('product_id');
            $form->text('amount');

            $form->display('created_at');
            $form->display('updated_at');

            $form->deleting(function (Form $form){
                global $__MINI_GLOBAL_TENANT_ID__;
                if($__MINI_GLOBAL_TENANT_ID__ > 0){
                    return $form->response()->error('权限不足，不可以删除其他分站对象');
                }
            });

        });
    }
}
